<template>
  <el-container class='elheight'>
    <el-aside class='appTree'>
      <app-tree :tree-data="treeData" v-on:appTreeClick="appTreeClick"></app-tree>
    </el-aside>
    <el-main>
      <el-container>
        <el-header class="dzy-main-header">
          <div class="btn-group-el">
            <btn-group :currentSelectedData="currentSelectedData" @btnClickCallback="btnClickCallback"></btn-group>
          </div>
          <div class="dzy-custom-search-box">
            <div>
              公民身份证号：<el-input placeholder="请输入内容" v-model="selectForm.identityNumber" clearable class="dzy-custom-input"></el-input>
            </div>
            <div>
              姓名：<el-input placeholder="请输入内容" v-model="selectForm.name" clearable class="dzy-custom-input"></el-input>
            </div>
            <div>
              性别：
              <el-select v-model="selectForm.gender" clearable placeholder="请选择">
                <el-option v-for="(item,index) in genderOption" :key="index" :label="item.name" :value="item.code"></el-option>
              </el-select>&nbsp;
            </div>
            <div>
              联系方式：<el-input placeholder="请输入内容" v-model="selectForm.phone" clearable class="dzy-custom-input"></el-input>
            </div>
            <div>
              政治面貌：
              <el-select v-model="selectForm.politicalStatus" clearable placeholder="请选择" filterable>
                <el-option v-for="(item,index) in politicalStatusOption" :key="index" :label="item.name" :value="item.code"></el-option>
              </el-select>
            </div>
            <div>
              留守人员类型：
              <el-select v-model="selectForm.leftBehindType" clearable placeholder="请选择" filterable>
                <el-option v-for="(item,index) in leftBehindTypeOption" :key="index" :label="item.name" :value="item.code"></el-option>
              </el-select>
            </div>
            <div>
              健康状况：
              <el-select v-model="selectForm.health" clearable placeholder="请选择" filterable>
                <el-option v-for="(item,index) in healthOption" :key="index" :label="item.name" :value="item.code"></el-option>
              </el-select>
            </div>
            <div>
              <el-button @click="searchHandleClick" type="primary" icon="el-icon-search">查询</el-button>
            </div>
          </div>
        </el-header>
        <el-main>
          <app-table
            :page-data="pageData"
            :table-columns="tableColumns"
            v-on:currentChange="handleCurrentChange"
            v-on:handleCheckedRows="handleCheckedRows">
          </app-table>
          <el-dialog :title="dialogTitle"
            :visible.sync="dialogFormVisible"
            class="custom-dialog_style" :before-close="cancel" :close-on-click-modal="false">
            <el-form :model="formData" :rules="rules" :disabled="showOnly" ref="formData">
              <el-collapse v-model="activeName" accordion class="custom-collapse-style">
                <el-collapse-item title="户籍基本信息" name="1">
                  <el-form-item label="公民身份号码：" prop="identityNumber">
                    <el-input v-model="formData.identityNumber" autocomplete="off" @blur="identityNumberHaveDone(formData.identityNumber)"></el-input>
                  </el-form-item>
                  <el-form-item label="姓名：" prop="name">
                    <el-input v-model="formData.name" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="曾用名：">
                    <el-input v-model="formData.usedName" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="性别：" prop="gender">
                    <el-select v-model="formData.gender" clearable placeholder="请选择">
                      <el-option v-for="(item,index) in genderOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="出生年月：" prop="birthday">
                    <el-date-picker
                      v-model="formData.birthday"
                      value-format="timestamp"
                      format="yyyy 年 MM 月 dd 日"
                      placeholder="选择日期时间"
                      :picker-options="dataPickerBeforeTodayOptions">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item label="民族：" prop="nation">
                    <el-select v-model="formData.nation" clearable placeholder="请选择" filterable>
                      <el-option v-for="(item,index) in nationOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="籍贯：" prop="birthplace">
                    <el-input v-model="formData.birthplace" clearable autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="婚姻状况：" prop="maritalStatusArr">
                    <div class="block">
                      <el-cascader
                        v-model="formData.maritalStatusArr"
                        placeholder="请选择"
                        :options="maritalStatusOption"
                        filterable
                        :props="dictProps"
                        clearable
                        :show-all-levels="false">
                      </el-cascader>
                    </div>
                  </el-form-item>
                  <el-form-item label="政治面貌：">
                    <el-select v-model="formData.politicalStatus" clearable placeholder="请选择" filterable>
                      <el-option v-for="(item,index) in politicalStatusOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="学历：" prop="educationArr">
                    <div class="block">
                      <el-cascader
                        v-model="formData.educationArr"
                        placeholder="请选择"
                        :options="educationOption"
                        filterable
                        :props="dictProps"
                        clearable
                        :show-all-levels="false">
                      </el-cascader>
                    </div>
                  </el-form-item>
                  <el-form-item label="宗教信仰：">
                    <el-select v-model="formData.religion" clearable placeholder="请选择" filterable>
                      <el-option v-for="(item,index) in religionOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="职业类别：">
                    <el-select v-model="formData.careerCategory" clearable placeholder="请选择" filterable>
                      <el-option v-for="(item,index) in careerCategoryOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="职业：">
                    <el-input v-model="formData.career" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="服务处所：">
                    <el-input v-model="formData.servicePlace" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="联系方式：" prop="phone">
                    <el-input v-model="formData.phone" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="户籍地：">
                    <el-input v-model="formData.householdAddr" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="户籍门(楼)详址：">
                    <el-input v-model="formData.householdAddrDetail" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="现住地：">
                    <el-input v-model="formData.currentAddr" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="现住门(楼)详址：">
                    <el-input v-model="formData.currentAddrDetail" autocomplete="off"></el-input>
                  </el-form-item>
                </el-collapse-item>
                <el-collapse-item title="留守信息" name="2">
                  <el-form-item label="健康状况：">
                    <el-select v-model="formData.health" clearable placeholder="请选择" filterable>
                      <el-option v-for="(item,index) in healthOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="个人年收入：">
                    <el-input v-model="formData.annualIncome" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="人户一致标识：">
                    <el-select v-model="formData.householdMark" clearable placeholder="请选择" filterable>
                      <el-option v-for="(item,index) in householdMarkOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="留守人员类型：">
                    <el-select v-model="formData.leftBehindType" clearable placeholder="请选择" filterable>
                      <el-option v-for="(item,index) in leftBehindTypeOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="家庭主要成员身份号码：">
                    <el-input v-model="formData.houseHolderIdentity" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="家庭主要成员姓名：">
                    <el-input v-model="formData.houseHolderName" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="家庭主要成员健康状况：">
                    <el-select v-model="formData.houseHolderHealth" clearable placeholder="请选择" filterable>
                      <el-option v-for="(item,index) in healthOption" :key="index" :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="与留守人员关系：">
                    <div class="block">
                      <el-cascader
                        v-model="formData.relationshipArr"
                        placeholder="请选择"
                        :options="relationshipOption"
                        filterable
                        :props="dictProps"
                        clearable
                        :show-all-levels="false">
                      </el-cascader>
                    </div>
                  </el-form-item>
                  <el-form-item label="家庭主要成员联系方式：">
                    <el-input v-model="formData.houseHolderPhone" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="家庭主要成员工作详细地址：">
                    <el-input v-model="formData.houseHolderWorkplace" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="家庭年收入：">
                    <el-input v-model="formData.familyAnnualIncome" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="困难及诉求：">
                    <el-input v-model="formData.trouble" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="帮扶情况：">
                    <el-input v-model="formData.helpSituation" autocomplete="off"></el-input>
                  </el-form-item>
                </el-collapse-item>
                <el-collapse-item title="现住地信息" name="3">
                  <el-form-item label="街道/社区/网格：" prop="gridIdArr">
                    <el-cascader
                      placeholder="请选择"
                      :options="treeData"
                      filterable
                      :props="gridIdProps"
                      :show-all-levels="false"
                      clearable @change="afterGridIdCheck"
                      v-model="formData.gridIdArr">
                    </el-cascader>
                  </el-form-item>
                  <el-form-item label="现居住地类型：">
                    <el-radio-group v-model="livePlaceType" size="medium" @change="livePlaceTypeChangedEvt">
                      <el-radio-button label="小区" ></el-radio-button>
                      <el-radio-button label="院落"></el-radio-button>
                    </el-radio-group>
                  </el-form-item>
                  <el-form-item label="院落：" v-if="isLiveYardSelectShow">
                    <el-select v-model="formData.liveCourtyardId" clearable filterable placeholder="请选择">
                      <el-option v-for="(liveYard,index) in liveYardOptions" :key="index" :label="liveYard.name" :value="liveYard.id"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="小区：" v-if="isLiveCommunitySelectShow">
                    <el-select v-model="formData.communityId" clearable placeholder="请选择" filterable @change="afterCommunityIdCheck">
                      <el-option v-for="(community,index) in communityOptions" :key="index" :label="community.name" :value="community.id"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="楼栋：" v-if="isLiveCommunitySelectShow">
                    <el-select v-model="formData.buildingId" clearable placeholder="请选择" filterable @change="afterBuildIdCheck">
                      <el-option v-for="(build,index) in buildingOptions" :key="index" :label="build.buildingName" :value="build.id"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="单元：" v-if="isLiveCommunitySelectShow">
                    <el-select v-model="formData.unitId" clearable placeholder="请选择" filterable @change="afterUnitIdCheck">
                      <el-option v-for="(unit,index) in unitOptions" :key="index" :label="unit.unitName" :value="unit.id"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="房屋：" v-if="isLiveCommunitySelectShow">
                    <el-select v-model="formData.liveHouseId" clearable placeholder="请选择" filterable>
                      <el-option v-for="(house,index) in houseOptions" :key="index" :label="house.houseNumber" :value="house.id"></el-option>
                    </el-select>
                  </el-form-item>
                </el-collapse-item>
              </el-collapse>
            </el-form>
            <div slot="footer" class="dialog-footer" v-if="isfooterBtnShow">
              <el-button @click="cancel">取 消</el-button>
              <el-button type="primary" @click="save('formData')">确 定</el-button>
            </div>
          </el-dialog>
        </el-main>
      </el-container>
    </el-main>
  </el-container>
</template>

<script>
import AppTree from '@/components/common/AppTree'
import AppTable from '@/components/AppTable'
import BtnGroup from '@/components/BtnGroup'
import {getAllRegion} from '@/utils/region'
import {validateIdefer} from '@/utils/validate'
import {getUserGridTree} from '@/utils/SessionDataUtil'
import {getDictDataOption} from '@/utils/getDictDataOption'
import {findCommunityList, findBuildingList, findUnitList, findHouseList, getHouse, findCourtyardList} from '@/http/FangWuGuanLiApi'
import {findLeftBehindPopulation, createLeftBehindPopulation, updateLeftBehindPopulation, delLeftBehindPopulation, getDetailLeftBehindPopulation, getPopulation} from '@/http/PopulationApi'
export default {
  data () {
    return {
      activeName: '1',
      dialogFormVisible: false,
      isfooterBtnShow: true,
      treeData: [],
      pageData: {},
      dialogTitle: '',
      currentSelectedData: [],
      showOnly: false,
      tableColumns: [
        { prop: 'name', label: '姓名' },
        { prop: 'identityNumber', label: '公民身份号码' },
        { prop: 'gender', label: '性别', formatter: this.genderFormatter },
        { prop: 'phone', label: '联系方式' },
        { prop: 'nation', label: '民族', formatter: this.nationFormatter, width: '70' },
        { prop: 'birthplace', label: '籍贯' }
      ],
      dataPickerBeforeTodayOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      },
      tableDada: [],
      formData: {},
      selectForm: {},
      communityOptions: [],
      buildingOptions: [],
      unitOptions: [],
      houseOptions: [],
      gridIdProps: {
        label: 'name',
        value: 'id',
        checkStrictly: true
      },
      dictProps: {
        label: 'name',
        value: 'code',
        checkStrictly: true
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        birthday: [
          { required: true, message: '请选择出生日期', trigger: 'blur' }
        ],
        identityNumber: [
          { validator: validateIdefer, required: true, trigger: 'blur' }
        ],
        gender: [
          { required: true, message: '请选择性别', trigger: 'blur' }
        ],
        nation: [
          { required: true, message: '请选择民族', trigger: 'blur' }
        ],
        birthplace: [
          { required: true, message: '请输入籍贯', trigger: 'blur' }
        ],
        maritalStatusArr: [
          { required: true, message: '请选择婚姻状况', trigger: 'blur' }
        ],
        educationArr: [
          { required: true, message: '请选择学历', trigger: 'blur' }
        ],
        gridIdArr: [
          { required: true, message: '请选择网格', trigger: 'blur' }
        ]
      },
      genderOption: [],
      nationOption: [],
      maritalStatusOption: [],
      politicalStatusOption: [],
      educationOption: [],
      religionOption: [],
      careerCategoryOption: [],
      healthOption: [],
      householdMarkOption: [],
      leftBehindTypeOption: [],
      relationshipOption: [],
      livePlaceType: '小区',
      isLiveYardSelectShow: false,
      isLiveCommunitySelectShow: true,
      liveYardOptions: []
    }
  },
  components: {
    AppTree,
    BtnGroup,
    AppTable
  },
  mounted () {
    this.genderOption = getDictDataOption('性别')
    this.politicalStatusOption = getDictDataOption('政治面貌')
    this.healthOption = getDictDataOption('健康状况')
    this.leftBehindTypeOption = getDictDataOption('留守人员类型')
    this.getTreeData()
    this.getTableData()
  },
  methods: {
    livePlaceTypeChangedEvt (val) {
      if (val) {
        let m = this
        const getPlaceType = {
          '小区': function () {
            m.isLiveYardSelectShow = false
            m.isLiveCommunitySelectShow = true
          },
          '院落': function () {
            if (m.liveYardOptions.length === 0 && m.formData.gridId && m.formData.gridId !== '') {
              m.getCourtyardList({likeAllGridId: m.formData.gridId})
            }
            m.isLiveYardSelectShow = true
            m.isLiveCommunitySelectShow = false
          }
        }
        getPlaceType[val]()
      }
    },
    // 格式化性别
    genderFormatter (row, column) {
      let genderOption = getDictDataOption('性别')
      let resGender = ''
      for (let i = 0; i < genderOption.length; i++) {
        if (genderOption[i].code === row.gender) {
          resGender = genderOption[i].name
          break
        }
      }
      return resGender
    },
    // 格式化民族
    nationFormatter (row, column) {
      let nationOption = getDictDataOption('民族')
      let resNation = ''
      for (let i = 0; i < nationOption.length; i++) {
        if (nationOption[i].code === row.nation) {
          resNation = nationOption[i].name
          break
        }
      }
      return resNation
    },
    identityNumberHaveDone (value) {
      getPopulation(value).then(resp => {
        if (resp.code && resp.code === '200') {
          let id = this.formData.id ? this.formData.id : null
          for (let key in resp.data) {
            if (key === 'id') continue
            this.$set(this.formData, key, resp.data[key])
          }
          let maritalStatusArr = this.formData.maritalStatusArr = this.formData.maritalStatus !== '' && this.formData.maritalStatus !== null ? this.formData.maritalStatus.split(',') : []
          let educationArr = this.formData.educationArr = this.formData.education !== '' && this.formData.education !== null ? this.formData.education.split(',') : []
          this.$set(this.formData, 'maritalStatusArr', maritalStatusArr)
          this.$set(this.formData, 'educationArr', educationArr)
          if (id !== null) this.$set(this.formData, 'id', id)
          if (this.formData.liveHouseId) {
            let houseId = this.formData.liveHouseId
            let m = this
            getHouse(houseId).then(resp => {
              if (resp.code && resp.code === '200') {
                m.afterCommunityIdCheck(resp.data.communityId)
                m.afterBuildIdCheck(resp.data.buildingId)
                m.afterUnitIdCheck(resp.data.unitId)
                m.afterGridIdCheck(resp.data.gridId)
                m.$set(m.formData, 'unitId', resp.data.unitId)
                m.$set(m.formData, 'buildingId', resp.data.buildingId)
                m.$set(m.formData, 'communityId', resp.data.communityId)
              }
            })
            let regionData = {}
            regionData.id = this.formData.liveGridId
            regionData.items = this.treeData
            let gridIdArr = getAllRegion(regionData)
            this.$set(this.formData, 'gridIdArr', gridIdArr)
          }
        } else {
          return ''
        }
      })
    },
    getCourtyardList (param) {
      let m = this
      findCourtyardList(param).then(resp => {
        if (resp.code && resp.code === '200') {
          let data = resp.data
          if (data && data instanceof Array) {
            m.liveYardOptions = data
          }
        } else {
          return ''
        }
      })
    },
    afterGridIdCheck (gridId) {
      if (gridId && gridId !== '') {
        this.getCourtyardList({likeAllGridId: gridId})
        findCommunityList({likeAllGridId: gridId}).then(resp => {
          if (resp.code && resp.code === '200') {
            this.communityOptions = resp.data
          } else {
            return ''
          }
        })
      } else {
        if (this.formData.gridIdArr && this.formData.gridIdAr.length > 0) {
          let gridArr = this.formData.gridIdArr
          let index = gridArr.length - 1
          let param = {
            likeAllGridId: gridArr[index]
          }
          this.getCourtyardList(param)
          findCommunityList(param).then(resp => {
            if (resp.code && resp.code === '200') {
              this.communityOptions = resp.data
            } else {
              return ''
            }
          })
        } else {
          this.communityOptions = []
          this.liveYardOptions = []
          this.$set(this.formData, 'liveCourtyardId', '')
          this.$set(this.formData, 'communityId', '')
          this.$set(this.formData, 'buildingId', '')
          this.$set(this.formData, 'unitId', '')
          this.$set(this.formData, 'liveHouseId', '')
        }
      }
    },
    afterCommunityIdCheck (val) {
      if (val) {
        let param = {communityId: val}
        findBuildingList(param).then(resp => {
          if (resp.code && resp.code === '200') {
            this.buildingOptions = resp.data
          } else {
            return ''
          }
        })
      }
    },
    afterBuildIdCheck (val) {
      if (val) {
        let param = {buildingId: val}
        findUnitList(param).then(resp => {
          if (resp.code && resp.code === '200') {
            this.unitOptions = resp.data
          } else {
            return ''
          }
        })
      }
    },
    afterUnitIdCheck (val) {
      if (val) {
        let param = {unitId: val}
        findHouseList(param).then(resp => {
          if (resp.code && resp.code === '200') {
            this.houseOptions = resp.data
          } else {
            return ''
          }
        })
      }
    },
    getTreeData () {
      let data = getUserGridTree()
      if (data && data instanceof Array) {
        this.treeData = data
      }
    },
    save (formName) {
      this.$refs[formName].validate((valid) => {
        if (!valid) {
          this.$alert('请填写正确表单格式', '', {
            confirmButtonText: '确定'
          })
          return ''
        } else {
          if (this.formData.gridIdArr && this.formData.gridIdArr !== 0) {
            let liveIndex = this.formData.gridIdArr.length - 1
            let liveData = {}
            liveData.id = this.formData.gridIdArr[liveIndex]
            liveData.items = this.treeData
            liveData.isGetAllId = true
            this.formData.liveAllGridId = getAllRegion(liveData)
          } else {
            this.formData.liveAllGridId = ''
          }
          this.formData.maritalStatus = this.formData.maritalStatusArr ? this.formData.maritalStatusArr.join(',') : ''
          this.formData.education = this.formData.educationArr ? this.formData.educationArr.join(',') : ''
          this.formData.relationship = this.formData.relationshipArr ? this.formData.relationshipArr.join(',') : ''
          if (this.formData.id) {
            updateLeftBehindPopulation(this.formData).then(resp => {
              if (resp.code && resp.code === '200') {
                this.dialogFormVisible = false
                this.$message({
                  type: 'success',
                  message: '修改成功'
                })
                this.getTableData()
              }
            })
          } else {
            createLeftBehindPopulation(this.formData).then(resp => {
              if (resp.code && resp.code === '200') {
                this.dialogFormVisible = false
                this.$message({
                  type: 'success',
                  message: '添加成功'
                })
                this.getTableData()
              }
            })
          }
        }
      })
    },
    del (rows) {
      if (rows && rows instanceof Array && rows.length > 0) {
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          rows.forEach(row => {
            delLeftBehindPopulation(row).then(resp => {
              if (resp.code && resp.code === '200') {
                this.$message({
                  type: 'success',
                  message: '删除成功'
                })
                this.getTableData()
              }
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    },
    cancel () {
      this.dialogFormVisible = false
      this.formData = {}
    },
    getTableData (param) {
      findLeftBehindPopulation(param).then(resp => {
        if (resp.code && resp.code === '200') {
          this.pageData = resp.data
          if (this.pageData.items && this.pageData.items instanceof Array) {
            this.tableData = this.pageData.items
          }
        }
      })
    },
    handleCurrentChange (val) {
      this.selectForm.offset = (val - 1) * 10
      this.getTableData(this.selectForm)
    },
    btnClickCallback (callbackData) {
      if (callbackData.btnType === 'delete') {
        this.dialogFormVisible = false
        let rows = callbackData.rows
        this.del(rows)
      } else {
        this.isfooterBtnShow = callbackData.btnType !== 'get'
        this.genderOption = getDictDataOption('性别')
        this.nationOption = getDictDataOption('民族')
        this.maritalStatusOption = getDictDataOption('婚姻状况')
        this.educationOption = getDictDataOption('学历')
        this.religionOption = getDictDataOption('宗教信仰')
        this.careerCategoryOption = getDictDataOption('职业分类')
        this.healthOption = getDictDataOption('健康状况')
        this.householdMarkOption = getDictDataOption('人户一致标识')
        this.relationshipOption = getDictDataOption('家庭关系')
        if (callbackData.btnType === 'post') {
          this.dialogTitle = '新增'
          if (this.formData.gridIdArr) {
            let arr = this.formData.gridIdArr
            this.formData = {}
            this.$set(this.formData, 'gridIdArr', arr)
          } else {
            this.formData = {}
          }
          this.showOnly = callbackData.sohwOnly
          this.dialogTitle = callbackData.dialogTitle
          this.dialogFormVisible = true
        } else {
          let _this = this
          getDetailLeftBehindPopulation(callbackData.rows[0].id).then(resp => {
            if (!resp.code && resp.code !== '200') {
              _this.$message({
                type: 'info',
                message: resp.message
              })
              return ''
            }
            let obj = JSON.stringify(resp.data)
            _this.formData = JSON.parse(obj)
            this.isLiveYardSelectShow = !!this.formData.liveCourtyardId && this.formData.liveCourtyardId !== ''
            this.isLiveCommunitySelectShow = !this.isLiveYardSelectShow
            if (this.formData.liveHouseId) {
              let houseId = this.formData.liveHouseId
              getHouse(houseId).then(resp => {
                if (resp.code && resp.code === '200') {
                  this.afterCommunityIdCheck(resp.data.communityId)
                  this.afterBuildIdCheck(resp.data.buildingId)
                  this.afterUnitIdCheck(resp.data.unitId)
                  this.afterGridIdCheck(resp.data.gridId)
                  this.$set(this.formData, 'unitId', resp.data.unitId)
                  this.$set(this.formData, 'buildingId', resp.data.buildingId)
                  this.$set(this.formData, 'communityId', resp.data.communityId)
                }
              })
            }
            let maritalStatusArr = this.formData.maritalStatus !== '' && this.formData.maritalStatus !== null ? this.formData.maritalStatus.split(',') : []
            let educationArr = this.formData.education !== '' && this.formData.education !== null ? this.formData.education.split(',') : []
            let relationshipArr = this.formData.relationship !== '' && this.formData.relationship !== null ? this.formData.relationship.split(',') : []
            this.$set(this.formData, 'maritalStatusArr', maritalStatusArr)
            this.$set(this.formData, 'educationArr', educationArr)
            this.$set(this.formData, 'relationshipArr', relationshipArr)
            let regionData = {}
            regionData.id = this.formData.liveGridId
            regionData.items = this.treeData
            let gridIdArr = getAllRegion(regionData)
            this.$set(this.formData, 'gridIdArr', gridIdArr)
            this.showOnly = callbackData.sohwOnly
            this.dialogTitle = callbackData.dialogTitle
            this.dialogFormVisible = true
          })
        }
      }
    },
    handleCheckedRows (rows) {
      if (rows && rows instanceof Array && rows.length > 0) {
        this.currentSelectedData = rows
      } else {
        this.currentSelectedData = []
      }
    },
    appTreeClick (data) {
      let gridData = {}
      gridData.id = data.id
      gridData.items = this.treeData
      let gridIdArr = getAllRegion(gridData)
      this.$set(this.formData, 'gridIdArr', gridIdArr)
      this.afterGridIdCheck(data.id)
      this.selectForm.likeAllGridId = data.id
      this.selectForm.offset = 0
      this.getTableData(this.selectForm)
    },
    searchHandleClick () {
      this.selectForm.offset = 0
      this.getTableData(this.selectForm)
    }
  }
}
</script>
<style>
.custom-severed-style{
  width: 100%;
  padding: 0;
  margin: 0 0 10px 20px;
  border-bottom: 2px solid rgb(101, 101, 216);
}
.custom-severed-style span{
  display: inline-block;
  padding: 6px 10px;
  color: white;
  background-color: rgb(101, 101, 216);
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
}
</style>
